package com.tech.koufu.ui.view;

import com.tech.koufu.MainActivity;
import com.tech.koufu.R;
import com.tech.koufu.ui.activity.ExpertsActivity;
import com.tech.koufu.ui.activity.menu.MyTrackActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;

/**
 * 牛人fragment
 * 
 * @author jl_luo
 *
 */
public class ExpertsContentFragment extends Fragment implements OnClickListener{
	private View rootView;
	private static final String TAG = ExpertsContentFragment.class.getName();
	// static ExpertsContentFragment newInstance(int num) {
	// ExpertsContentFragment f = new ExpertsContentFragment();
	// // Supply num input as an argument.
	// Bundle args = new Bundle();
	// args.putInt("num", num);
	// f.setArguments(args);
	//
	// return f;
	// }

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (rootView == null) {Log.d(TAG, "~~~~~~ExpertsContentFragment~~~onCreateView~~~~~~~");
			rootView = inflater
					.inflate(R.layout.fragment_experts_content, container,false);
			initView();
		}else{
			Log.d(TAG, "~~~~no~ExpertsContentFragment~onCreateView~~~~~~~~~~");
		}
		// 缓存的rootView需要判断是否已经被加过parent，
		// 如果有parent需要从parent删除，要不然会发生这个rootview已经有parent的错误。
		ViewGroup parent = (ViewGroup) rootView.getParent();
		if (parent != null) {
			parent.removeView(rootView);
		}
		
		return rootView;
		// return inflater.inflate(R.layout.tab_experts, container,
		// false);//super.onCreateView(inflater, container, savedInstanceState);
	}

	private void initView() {
		 rootView.findViewById(R.id.rl_title_experts_focused).setOnClickListener(this);
		 rootView.findViewById(R.id.rl_title_experts_profitableman).setOnClickListener(this);
		 rootView.findViewById(R.id.rl_title_experts_popularityranking).setOnClickListener(this); 
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	@Override
	public void onClick(View v) {
		 switch (v.getId()) {
		case R.id.rl_title_experts_focused:
			Intent intent = new Intent(getActivity(),MyTrackActivity.class);  
			startActivity(intent);
			break;
		case R.id.rl_title_experts_profitableman:
			intent = new Intent(getActivity(),ExpertsActivity.class);
			intent.putExtra("status", 1);
			startActivity(intent);
			break;
		case R.id.rl_title_experts_popularityranking:
			intent = new Intent(getActivity(),ExpertsActivity.class);
			intent.putExtra("status", 2);
			startActivity(intent);
			break;

		default:
			break;
		}
		
	}

}
